package com.example.treeutil.layer;


import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;

import java.util.ArrayList;
import java.util.List;

/**
 * 2024/12/13
 * 资源目录对象，多级目录，自包含，树的枝节点
 * @author fengyu
 */
@NodeType
@JsonInclude(JsonInclude.Include.NON_NULL)
public class MuLu implements TreeNode<String, String, MuLu>{
    private String id;

    private String name;

    // 是否展开
    private boolean open;

    // 同级目录中的次序，数据库层面不要做唯一限定
    private int index;

    private MuLu parent;

    private List<MuLu> subs = new ArrayList<>();

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isOpen() {
        return open;
    }

    public void setOpen(boolean open) {
        this.open = open;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    // 自包含对象直接转json时一定把获取父对象的get方法忽略掉
    @JsonIgnore
    public MuLu getParent() {
        return parent;
    }

    public void setParent(MuLu parent) {
        this.parent = parent;
    }

    public void setSubs(List<MuLu> subs) {
        this.subs = subs;
    }

    @Override
    public String getPId() {
        if (null == parent) return null;
        return parent.getId();
    }

    @Override
    public List<MuLu> getSubs(){
        return this.subs;
    }

    @Override
    public String getId() {
        return id;
    }
}
